% array is ordered as follows
% array = [X11 Y11 Z11 X21 Y21 Z21 .... X12 Y12 Z12 X22 Y22 Z22 ....];

function array = tensor2array(tensor),
% We assume a square grid
N=length(tensor(:,1,1));
array=zeros(N^2*3,1);
for i=1:N,
    for j=1:N,
        array((i+N*(j-1))*3-2:(i+N*(j-1))*3,1)=tensor(i,j,:);
    end
end

